// components/system/expert_list/expert_list.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        page: 1,
        total: 0,
        size: 5,
        isLoadedAll: false,

        expertList: [],
    },

    /**
     * 组件的方法列表
     */
    methods: {
        detail(e){
            console.log(e.currentTarget.dataset.id)
            wx.navigateTo({
              url: `/pkgA/expert_detail/expert_detail?id=${e.currentTarget.dataset.id}`,
            })
        },
        onChange(e) {
            this.setData({
                value: e.detail,
            });
            console.log("内容变化", this.data.value)
        },
        onSearch() {
            console.log("确定搜索", this.data.value)
        },

        reachBottomLoad() {
                       //如果数据都加载完
                       if ((this.data.page - 1) * this.data.size >= this.data.total) {
                        this.setData({
                            isLoadedAll: true
                        })
                        console.log("加载完了！！")
                        return
                    }
        
                    // 节流阀
                    if (!this.data.isLoading) {
                        this.setData({
                            isLoading: true
                        })
        
                        wx.showLoading({
                            title: '加载中...',
                        })
        
                        wx.request({
                            url: `http://120.77.156.205:8808/wx/expert/getexpert/${this.data.page}/${this.data.size}
                        `,
                            method: 'POST',
                            data: {
                            },
                            success: (res) => {
                                // console.log(res.data)
                                if (res.data.code == 0) {
                                    this.setData({
                                        expertList: [...this.data.expertList, ...res.data.data.rows],
                                        page: this.data.page + 1,
                                        total: res.data.data.total
                                    })
                                    // console.log(this.data.fishBaiKeList)
                                }
                            }
                        })
        
                        wx.hideLoading({
                            success: (res) => { },
                        })
        
                        //如果数据都加载完
                        if ((this.data.page - 1) * this.data.size >= this.data.total) {
                            this.setData({
                                isLoadedAll: true
                            })
                        }
        
                    }
                    this.setData({
                        isLoading: false
                    })
        },
    },

    lifetimes: {
        attached: function () {
            wx.request({
                url: `http://120.77.156.205:8808/wx/expert/getexpert/${this.data.page}/${this.data.size}`,
                method: 'POST',
                data: {

                },
                success: (res) => {
                    this.setData({
                        expertList: [...this.data.expertList, ...res.data.data.rows],
                        page: this.data.page + 1,
                        total: res.data.data.total
                    })
                    console.log(this.data.expertList)
                    if (this.data.total <= this.data.size) {
                        this.setData({
                            isLoadedAll: true
                        })
                    }
                },
                fail:(err)=>{
                    console.log(err)
                    wx.showToast({
                      title: '服务器网络异常',
                      icon:'none'
                    })
                }
            })
        }


    }


})
